package com.yantong.service.impl;

import com.yantong.pojo.MemberRole;
import com.yantong.enums.MemberRoleEnum;
import com.yantong.mapper.MemberRoleMapper;
import com.yantong.service.MemberRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liaozhaogui
 * @description: MemberRoleServiceImpl
 * @date 2020/9/18 15:07
 */
@Service
public class MemberRoleServiceImpl implements MemberRoleService {
	@Autowired
	private MemberRoleMapper memberRoleMapper;

	@Override
	public Integer insert(MemberRole memberRole) {
		if (memberRole == null) {
			return null;
		}
		String roleName = memberRole.getMemberRoleName();
		if(MemberRoleEnum.SUPERVISOR.getCode().equals(roleName) ||MemberRoleEnum.HOUSEKEEPER.getCode().equals(roleName)
				||MemberRoleEnum.TWITTER.getCode().equals(roleName)){
			memberRoleMapper.updateStatus(memberRole.getMemberId());
		}
		return memberRoleMapper.insert(memberRole);
	}

	@Override
	public List<String> queryList(Long memberId) {
		if (memberId == null) {
			return null;
		}
		List<MemberRole> list = memberRoleMapper.queryList(memberId);
		List<String> listResult = new ArrayList<>();
		for(MemberRole memberRole:list){
			listResult.add(memberRole.getMemberRoleName());
		}
		return listResult;
	}
}
